import javax.swing.*;

public class EmployeeSearch {
    public static void main(String[] args) {
        Employee[] employee = {
                new Employee("张三","经理",7000),
                new Employee("李四","员工",6000),
                new Employee("王五","会计",5000)
        };
        String name = JOptionPane.showInputDialog(null,"输入你要查找的员工姓名");

        //方法一
//        int index = -1;
//        for (int i=0;i<employee.length;i++){
//            if (name.equals(employee[i].name)){
//                index = i;
//                break;
//            }
//        }
//        if (index ==-1){
//            JOptionPane.showMessageDialog(null,"查无此人");
//        }
//        if (index != -1){
//            JOptionPane.showMessageDialog(null,employee[index].name+"  "+employee[index].job+"  "+employee[index].salary);
//        }

        //方法二
        Employee em = null;
        for (Employee e:employee){
            if (name.equals(e.name)){
                em = e;
                break;
            }
        }
        if (em == null){
            JOptionPane.showMessageDialog(null,"查无此人");
        }
        if (em != null){
            JOptionPane.showMessageDialog(null,em.name+"  "+em.job+"  "+em.salary);
        }



    }
}
